package com.kfm.hotel.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.kfm.hotel.domain.Room;
import com.kfm.hotel.domain.SysDict;
import com.kfm.hotel.service.MailService;
import com.kfm.hotel.service.RoomService;
import com.kfm.hotel.service.SysDictService;
import com.kfm.hotel.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@RestController
@RequestMapping("/checkin")
public class CheckinController {
    @Autowired
    private SysDictService sysDictService;
    @Autowired
    private RoomService roomService;

    /**
     * 入住视图
     * @return
     */

    @GetMapping
    public ModelAndView index(){
        ModelAndView modelAndView = new ModelAndView("checkin/index-vue");
        //查看房间所有状态(参数1获取字典中的数据：房间状态)
        modelAndView.addObject("roomStatusList",sysDictService.getByType(1));
        //查询所有楼层（参数2 获取字典中的楼层为sys_dict表中type为2的数据：楼层）
        List<SysDict> byType = sysDictService.getByType(2);
        modelAndView.addObject("floorList",byType);
//        //查询第一楼层的房间
        QueryWrapper<Room> wrapper = new QueryWrapper<>();
        wrapper.eq("floor",byType.get(0).getValue());
        //wrapper.eq("floor",byType.get(1).getValue());
        modelAndView.addObject("roomList",roomService.list(wrapper));
        return modelAndView;
    }
//    @GetMapping("/vue")
//    public ModelAndView vue(){
//       return new ModelAndView("checkin/index-vue");
//    }
    @GetMapping("/roomList")
    public R roomList(Integer floor){
        QueryWrapper<Room> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("floor",floor);
        List<Room> list = roomService.listDeep(queryWrapper);
        return R.ok(list);
    }

    /**
     * 获取房间状态信息
     * @return
     */
    @GetMapping("/roomStatusList")
    public R roomStatusList(){
        return R.ok(sysDictService.getByType(1));
    }
    /**
     * 获取楼层信息
     */
    @GetMapping("/floorList")
    public R floorList(){
        return R.ok(sysDictService.getByType(2));
    }
    /**
     * 入住登记
     */
    @GetMapping("/checkin/{id}")
    public ModelAndView checkin(@PathVariable Integer id){
        ModelAndView modelAndView = new ModelAndView("checkin/checkin");
        modelAndView.addObject("id",id);
        return modelAndView;

    }
}
